/* 
 * File:   User.cpp
 * Author: nstratos
 * 
 * Created on September 19, 2012, 9:45 PM
 */

#include <iostream>
#include "User.hpp"
#include "Server.hpp"
#include "TooManyCharactersException.hpp"

using namespace std;

const int User::MAX_CHARACTERS;

User::User(string username) {
    this->id = Server::generateUserId();
    this->username = username;
}

User::User(string username, int age) {
    this->id = Server::generateUserId();
    this->username = username;
    this->age = age;
}

User::User(const User& orig) {
    this->id = orig.id;
    this->username = orig.username;
    this->age = orig.age;
    this->password = orig.password;
}

User::~User() {
}

string User::getUsername() {
    return this->username;
}

void User::setUsername(string username) {
    this->username = username;
}

int User::getAge() {
    return this->age;
}

int User::getId() {
    return this->id;
}

void User::whoAmI() {
    //string str = "";
    //str += string("id: ") + this->id + "\n";
    //str += "Username: " + this->username + "\n";
    //str += "Age: " + this->age + "\n";
    cout << "id: " << this->id << endl;
    cout << "Username: " << this->username << endl;
    cout << "Age: " << this->age << endl;
    //cout << str;
}

Character* User::createRandomizedCharacter(std::string name) {
    if (this->characters.size() < this->MAX_CHARACTERS) {
        Character* c = new Character(name);
        this->characters.push_back(c);
        return c;
    } else {
        TooManyCharactersException tmce;
        throw tmce;
    }
}

void User::printCharacters() {
    for (int i = 0; i < this->characters.size(); i++) {
        Character* c = characters[i];
        cout << "Character name: " << c->getName() << endl;
    }
}

